home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Code Resources / sicn LDEF / sicn ldef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-15  |  2.9 KB  |  122 lines  |  [TEXT/KAHL]

  1. /*    SICN LDEF
  2.  
  3.     ©1991 Apple Computer, Inc.
  4.     written by Steven Falkenburg 5/23/91
  5.     This LDEF displays small icons to the left of text in a list.
  6.     
  7.     The small icon is stored in the first 32 bytes of each cell.
  8.     
  9.     modified by Matt Slot, 9/6/93
  10.         Fixed odd address problem in the SICN plotting
  11. */
  12.  
  13.  
  14. /* constants for spacing */
  15.  
  16. #define kLeftOffset    2
  17. #define kTopOffset    0
  18. #define kIconSpace    2
  19.  
  20. /* prototypes */
  21.  
  22. void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort);
  23.  
  24. /* main LDEF entry point */
  25.  
  26. pascal void    main(short lMessage,Boolean lSelect,Rect *lRect,Cell lCell,
  27.                 short lDataOffset,short lDataLen,ListHandle lHandle)
  28. {
  29.     FontInfo fontInfo;                        /* font information (ascent/descent/etc) */
  30.     ListPtr listPtr;                        /* pointer to store dereferenced list */
  31.     SignedByte hStateList,hStateCells;        /* state variables for HGetState/SetState */
  32.     Ptr cellData;                            /* points to start of cell data for list */
  33.     Ptr theSICN;                            /* points to SICN to be drawn */
  34.     short leftDraw,topDraw;                    /* left/top offsets from topleft of cell */
  35.     
  36.     #pragma unused (lCell)
  37.     
  38.     theSICN = NewPtr(32);
  39.     
  40.     /* lock and dereference list mgr handles */
  41.     
  42.     hStateList = HGetState((Handle) lHandle);
  43.     HLock((Handle) lHandle);
  44.     listPtr = *lHandle;
  45.     hStateList = HGetState(listPtr->cells);
  46.     HLock(listPtr->cells);
  47.     cellData = *(listPtr->cells);
  48.     
  49.     switch (lMessage) {
  50.       case lInitMsg:
  51.           /* we don't need any initialization */
  52.           break;
  53.  
  54.       case lDrawMsg:
  55.         EraseRect(lRect);
  56.         
  57.           if (lDataLen > 0) {
  58.           
  59.               /* determine starting point for drawing */
  60.               
  61.               leftDraw =    lRect->left+listPtr->indent.h+kLeftOffset;
  62.               topDraw =    lRect->top+listPtr->indent.v+kTopOffset;
  63.               
  64.               /* plot SICN (first 32 bytes) */
  65.               
  66.               if (lDataLen > 32) {
  67.                   BlockMove(cellData+lDataOffset, theSICN, 32);
  68.                   DrawSICN(theSICN,leftDraw,topDraw,listPtr->port);
  69.                   lDataOffset += 32;
  70.                   lDataLen -= 32;
  71.               }
  72.               leftDraw += 16+kIconSpace;
  73.               
  74.               /* plot text (offset 32 bytes onward) */
  75.               
  76.             GetFontInfo(&fontInfo);
  77.             MoveTo(leftDraw,topDraw+fontInfo.ascent);
  78.             
  79.             /* set condensed mode if necessary (if the text doesn't fit otherwise) */
  80.             
  81.             TextFace(0);
  82.             if (TextWidth(cellData,lDataOffset,lDataLen) > (lRect->right - leftDraw))
  83.                 TextFace(condense);
  84.  
  85.             DrawText(cellData,lDataOffset,lDataLen);
  86.           }
  87.  
  88.         if (!lSelect)
  89.               break;
  90.         
  91.       case lHiliteMsg:
  92.           /* do hilite color */
  93.           (* (char *) HiliteMode) ^= (1 << hiliteBit);
  94.           InvertRect(lRect);
  95.           break;
  96.  
  97.       case lCloseMsg:
  98.           break;
  99.     }
  100.     
  101.     DisposePtr(theSICN);
  102.     HSetState(listPtr->cells,hStateCells);
  103.     HSetState((Handle) lHandle,hStateList);
  104. }
  105.  
  106.  
  107. /* this procedure draws a small icon using CopyBits */
  108.  
  109. void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort)
  110. {
  111.     BitMap iconMap;
  112.     Rect destRect;
  113.  
  114.     iconMap.baseAddr = theSICN;
  115.     iconMap.rowBytes = 2;
  116.     SetRect(&iconMap.bounds,0,0,16,16);
  117.     SetRect(&destRect,0,0,16,16);
  118.     OffsetRect(&destRect,left,top);
  119.     CopyBits(&iconMap,&drawPort->portBits,&iconMap.bounds,&destRect,
  120.             srcCopy,nil);
  121. }
  122.